/**
* @file Mem_Alloc.c
* @author W. P. Yao, ywp@pku.edu.cn
* @version 0.0.1
* @date 2015-12-09
*/

/**
* @Name: Mem_Alloc 
* @Brief: R     -- time; 
		  C     -- space;
		  INDEX -- itera; 
		  p     -- fftw;
* 
*/


#include "Mem_Alloc.h"
void Mem_Alloc()
{
	R_rho     = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));	
	R_omega   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	
	C_rho     = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_rho_n   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_rho_o   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_rho_x   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_rho_y   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_u       = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_v       = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_omega   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_omega_n = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_omega_o = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_omega_x = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_omega_y = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_psi     = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_psi_x   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));
	C_psi_y   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(M*NUM));


	R_Add_u       = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_v       = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_rho_x   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_rho_y   = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_omega_x = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_omega_y = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_phi     = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));
	R_Add_psi     = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_M*Add_NUM));    
	

	/// Index j*Add_NUM+i
	C_INDEX = (int **)malloc(sizeof(int*)*(Add_M));
	for(i = 0; i < Add_M; i++){
		C_INDEX[i] = (int *)malloc(sizeof(int)*(Add_NUM));
	}	


	/// p for FFTW to save time
	in       = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_NUM));      ///Fourier, input array
	out      = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(Add_NUM));      ///Fourier, output array
	fftw_fp  = fftw_plan_dft_1d(Add_NUM, in, out, FFTW_FORWARD, FFTW_ESTIMATE);  ///Forward, R2C
	fftw_bp  = fftw_plan_dft_1d(Add_NUM, in, out, FFTW_BACKWARD, FFTW_ESTIMATE); ///Backward, C2C

	In       = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(NUM));
	Out      = (fftw_complex *)fftw_malloc(sizeof(fftw_complex)*(NUM));
	fftw_fip = fftw_plan_dft_1d(NUM, In, Out, FFTW_FORWARD, FFTW_ESTIMATE);
	fftw_bop = fftw_plan_dft_1d(NUM, In, Out, FFTW_BACKWARD, FFTW_ESTIMATE);




}
